package com.ajnp.springcloud.service.impl;

import cn.hutool.core.lang.UUID;
import com.ajnp.springcloud.service.IMessageProvider;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.messaging.MessageChannel;

import javax.annotation.Resource;

//定义消息发送的管道
@EnableBinding(Source.class)
public class MessageProviderimpl implements IMessageProvider {

    @Resource
    private MessageChannel output;  //消息发送管道

    @Override
    public String send() {
        String serial = UUID.randomUUID().toString();
        output.send(MessageBuilder.withPayload(serial).build());
        System.out.println("*****serial:" + serial);
        return null;
    }

    //消息生产者服务构建（build）了一个Message消息对象，然后传给了Source池 再用管道Bingding传给消息中间件MQ，然后消息接受方的Sink池，它收到那个Message对象
}
